<template>
	<view class="container" :style="{paddingBottom:'75px' }">
		<tabBar numBer="3"></tabBar>
		<view class="userAvar">
			<!-- <image src="" mode=""></image> -->
			<view class="topHeacd"></view>
			<view class="biaoti f f-a-c p-l-30">
				<view @click="goCat" class="icons">
					<image src="/static/shoop/02@2x.png" class="avar m-r-10" mode=""></image>
					<view class="icon f f-a-c f-j-c">
						{{obj.shop_cart_num}}
					</view>
				</view>
			</view>
			<!-- <view class="box"> -->
			<view class="tab m-0-a f f-a-c f-j-b">
				<image src="/static/shoop/Frame@2x.png" class="sechImg" mode=""></image>
				<input type="text" :disabled="true" @click="goSche" class="inputs" placeholder="输入商品名称找找看" name=""
					id="">
				<!-- 	<text class="one">你好5644554</text>
			<text class="tow">你好</text>
			你好 -->
				<!-- </view> -->
			</view>
		</view>
		<!-- 下面的轮播图 -->
		<view class="swip m-t-20 p-l-20 p-r-20">
			<u-swiper height="262" border-radius="30" name="url" @click="swipClick" :list="list"></u-swiper>
			<view class="tabs m-0-a f f-a-c f-j-b">
				<view v-for="(item,index) in tabsList" class="life" @click="tabClick(item,index)"
					:class="{active:index==act}">
					<image v-show="index==act" src="/static/home/6.png" class="bgB" mode=""></image>
					{{item.name}}
				</view>
			</view>
			<view class="botSetil f f-a-c">
				<view class="Default" @click="clickDefault(0)" :class="{DefaultAct:active==0}">
					默认
				</view>
				<view class="shuXian m-l-20 m-r-20"></view>
				<view class="Default" @click="clickDefault(1)" :class="{DefaultAct:active==1}">
					销量
				</view>
				<view class="shuXian m-l-20 m-r-20"></view>
				<view class="Default" @click="clickDefault(2)" :class="{DefaultAct:active==2}">
					价格 <image src="/static/shoop/shai.png" v-if="shai==0" class="shai" mode=""></image>
					<image src="/static/shoop/shai1.png" v-if="shai==1" class="shai" mode=""></image>
					<image src="/static/shoop/shai2.png" v-if="shai==2" class="shai" mode=""></image>
				</view>
			</view>
			<!-- list -->
			<view class="listObj">
				<scroll-view scroll-y style="height: 100%;width: 100%;" :show-scrollbar="true" class="scoNone"
					@scrolltolower="onreachBottom">
					<view class="list f f-w-w f-a-c">
						<view v-for="(item,index) in shoopList" @click="goDetils(item,index)" class="listItem">
							<view class="boxImg">
								<image :src="item.cover" class="damaoImg" mode="aspectFill"></image>
							</view>
							<view class="content">
								{{item.name}}
							</view>
							<view class="price f f-a-c f-j-b">
								<view class="priceLeft">
									<text>￥</text>{{item.price}}
								</view>
								<view class="yishou">
									已售{{item.sales}}件
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				shai: 0,
				act: 0,
				active: 0,
				status: false,
				token: uni.getStorageSync('token'),
				tabsList: [{
					name: '猫粮',

				}, {
					name: '零食罐头',

				}, {
					name: '冻干零食',

				}, {
					name: '食具水具',

				}, {
					name: '清洁美容',

				}, {
					name: '食具水具',

				}],
				list: [{
						image: 'https://cdn.uviewui.com/uview/swiper/1.jpg',
						title: '昨夜星辰昨夜风，画楼西畔桂堂东'
					},
					{
						image: 'https://cdn.uviewui.com/uview/swiper/2.jpg',
						title: '身无彩凤双飞翼，心有灵犀一点通'
					},
					{
						image: 'https://cdn.uviewui.com/uview/swiper/3.jpg',
						title: '谁念西风独自凉，萧萧黄叶闭疏窗，沉思往事立残阳'
					}
				],
				obj: {},
				page: 1,
				total: '',
				shoopList: []
			}
		},
		async onShow() {
			this.page = 1
			this.shoopList = []
			await this.initObj()
			this.initList()
		},
		watch: {
			active(newVal, oldVal) {
				if (newVal != 2) {
					this.shai = 0
				}
			},
			status(newVal, oldVal) {
				if (this.active == 2) {
					if (newVal) {
						this.shai = 1
					} else {
						this.shai = 2
					}
				}
			}
		},
		methods: {
			// 跳转商品详情
			swipClick(e) {
				if (this.list[e].product_id) {
					uni.navigateTo({
						url: '/pages/shoop/shoopDetils?id=' + this.list[e].product_id
					})
				}
			},
			// 请求商城首页
			async initObj() {
				let n = await this.$api.shoopIndex()
				this.obj = n.data
				this.list = n.data.banner
				this.tabsList = n.data.categories
			},
			async initList() {
				let n = await this.$api.shoopList({
					page: this.page,
					q: '',
					category_id: this.tabsList[this.act].id,
					order_by: this.active == 0 ? 'default' : this.active == 1 ? 'sales' : 'price',
					direction: !this.status ? 'asc' : 'desc'
				})
				this.total = n.data.total
				this.shoopList = [...this.shoopList, ...n.data.rows]
			},
			// actactactactact
			// 去购物车
			goCat() {
				if (!this.token) {
					return this.$msg('请先登录')
				}
				uni.navigateTo({
					url: '/pages/shoop/ShoppingCart'
				})
			},
			// /去列表搜索
			goSche() {
				uni.navigateTo({
					url: '/pages/shoop/LookFor'
				})
			},
			goDetils(item, index) {
				uni.navigateTo({
					url: '/pages/shoop/shoopDetils?id=' + item.id
				})
			},
			onreachBottom() {
				if (this.shoopList.length < this.total) {
					this.page++
					this.initList()
				}
				console.log('123456789');
			},
			// 切换筛选
			clickDefault(num) {
				this.active = num
				this.status = !this.status
				this.page = 1
				this.shoopList = []
				this.initList()
			},
			tabClick(item, index) {
				this.act = index
				this.page = 1
				this.shoopList = []
				this.initList()
			}
		}
	}
</script>

<style scoped lang="scss">
	.listObj {
		height: 52vh;
		overflow-y: auto;


	}

	.scoNone::-webkit-scrollbar {
		display: none !important;
	}

	.list {
		.listItem {
			width: 49%;
			margin-right: 2%;
			background: #fffefc;
			margin-bottom: 25rpx;
			overflow: hidden;
			border-radius: 24rpx;
			padding-bottom: 20rpx;

			&:nth-child(2n) {
				margin-right: 0;
			}

			.boxImg {
				width: 100%;
				height: 332rpx;
				background: #ffffff;
				border-radius: 24rpx 24rpx 0rpx 0rpx;

				.damaoImg {
					width: 100%;
					height: 100%;
					object-fit: cover;
				}
			}

			.content {
				padding: 0 15rpx;
				font-size: 26rpx;
				font-family: PingFang SC, PingFang SC-400;
				font-weight: 500;
				text-align: LEFT;
				height: 75rpx;
				color: $hei;
				margin-top: 15rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
			}

			.price {
				margin-top: 20rpx;
				padding: 0 15rpx;

				.priceLeft {
					font-size: 32rpx;
					font-family: HarmonyOS Sans, HarmonyOS Sans-700;
					font-weight: 700;
					text-align: CENTER;
					color: $brown;

					text {
						font-size: 24rpx;
					}
				}

				.yishou {
					font-size: 20rpx;
					font-family: PingFang SC, PingFang SC-400;
					font-weight: 400;
					text-align: LEFT;
					color: $hui;
				}
			}
		}
	}

	.swip {
		height: 100%;
	}

	.botSetil {
		padding: 20rpx 20rpx;


		.Default {
			font-size: 26rpx;
			font-family: PingFang SC, PingFang SC-400;
			font-weight: 600;
			text-align: LEFT;
			color: $hui;

			.shai {
				width: 18rpx;
				height: 22rpx;
				margin-left: 10rpx;
			}
		}

		.shuXian {
			width: 0rpx;
			height: 24rpx;
			border-left: 1rpx solid #ebe2da;
		}

		.DefaultAct {
			color: $hei !important;
		}

	}

	.tabs {
		width: 100%;
		margin-top: 60rpx;
		overflow-x: auto;

		.life {
			position: relative;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC-500;
			font-weight: 500;
			text-align: CENTER;
			margin-right: 50rpx;
			color: $hui;
			flex-shrink: 0;

			.bgB {
				position: absolute;
				width: 60rpx;
				height: 52rpx;
				top: -10rpx;
				left: -10rpx;
			}
		}

		.active {
			font-size: 36rpx;
			font-weight: 600;
			text-align: CENTER;
			color: $hei;
		}
	}

	.tabs::-webkit-scrollbar {
		display: none !important;
	}

	.container {
		height: 100vh;
		width: 100%;
		padding-top: 180rpx;
		overflow-y: auto;
		background-color: #f7f6f2;
	}

	.container::-webkit-scrollbar {
		display: none !important;
	}

	.userAvar {
		position: fixed;
		top: 0%;
		left: 0;
		height: 180rpx;
		width: 100%;
		background: #fffefc;
		z-index: 99;
	}

	.topHeacd {
		height: 70rpx;
	}

	.biaoti {
		position: relative;
		height: 90rpx;
		width: 100%;

		.icons {
			position: relative;

			.icon {
				width: 36rpx;
				height: 36rpx;
				background: $brown;
				border: 2rpx solid #ffffff;
				border-radius: 20rpx;
				position: absolute;
				top: -15rpx;
				right: -10rpx;
				font-size: 20rpx;
				font-family: PingFang SC, PingFang SC-500;
				font-weight: 500;
				text-align: center;
				color: #ffffff;
			}
		}

		// background-color: pink;

		.avar {
			width: 40rpx;
			height: 40rpx;
		}

		.name {
			font-size: 30rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			color: #333333;
		}
	}

	.tab {
		position: absolute;
		top: 50%;
		left: 41%;
		transform: translateX(-50%);
		// margin-top: 60rpx;
		z-index: 10;

		.sechImg {
			width: 28rpx;
			height: 28rpx;
			position: absolute;
			left: 6%;
			// top: 50%;
			// left: 50%;
			// transform: translateX(-50%);
		}
	}

	.inputs {
		width: 408rpx;
		height: 64rpx;
		background: #f7f6f2;
		border-radius: 40rpx;
		padding-left: 64rpx;
		box-sizing: border-box;
	}

	.active {
		font-size: 36rpx;
		font-weight: 600;
		text-align: CENTER;
		color: $hei;
	}
</style>